package com.lizhen.structurepattern.filterpattern;

import com.lizhen.structurepattern.filterpattern.impl.*;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class FilterPattern {
    public FilterPattern() {
    }

    public static void main(String[] args) {
        List<Person> persons = new ArrayList();
        persons.add(new Person("Robert", "Male", "Single"));
        persons.add(new Person("John", "Male", "Married"));
        persons.add(new Person("Laura", "Female", "Married"));
        persons.add(new Person("Diana", "Female", "Single"));
        persons.add(new Person("Mike", "Male", "Single"));
        persons.add(new Person("Bobby", "Male", "Single"));
        Criteria male = new CriteriaMale();
        Criteria female = new CriteriaFemale();
        Criteria single = new CriteriaSingle();
        Criteria singleMale = new AndCriteria(single, male);
        Criteria singleOrFemale = new OrCriteria(single, female);
        System.out.println("Males: ");
        printPersons(male.meetCriteria(persons));
        System.out.println();
        System.out.println("Females: ");
        printPersons(female.meetCriteria(persons));
        System.out.println();
        System.out.println("Single Males: ");
        printPersons(singleMale.meetCriteria(persons));
        System.out.println();
        System.out.println("Single Or Females: ");
        printPersons(singleOrFemale.meetCriteria(persons));
    }

    public static void printPersons(List<Person> persons) {
        Iterator var2 = persons.iterator();

        while (var2.hasNext()) {
            Person person = (Person) var2.next();
            System.out.println("Person : [ Name : " + person.getName() + ", Gender : " + person.getGender() + ", Marital Status : " + person.getMaritalStatus() + " ]");
        }

    }
}
